#include "CentralTabWidget.h"
#include "CentralTabBar.h"
#include "CentralTabCloseButton.h"
#include "Tabs/CentralTab.h"

#include "EventHelper.h"
#include "Namespace.h"
#include "SystemHelper.h"

#include <QApplication>
#include <QDrag>
#include <QEvent>
#include <QGraphicsOpacityEffect>
#include <QLayout>
#include <QMimeData>
#include <QMouseEvent>
#include <QToolButton>

CentralTabWidget::CentralTabWidget(QWidget *parent) : BaseTabWidget(parent) {
    CentralTabBar *bar = new CentralTabBar();
    bar->setDrawBase(false);
    bar->setObjectName(QLatin1String("qt_tabwidget_tabbar"));
    setTabBar(bar);

    setMovable(true);
    setTabsClosable(true);
    setUsesScrollButtons(true);
    bar->setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab);

    setAcceptDrops(true);
}

CentralTabWidget::~CentralTabWidget() {
}

void CentralTabWidget::addTabCore(int index) {
    auto bar = tabBar();
    CentralTab *tab = tabAt(index);

    CentralTabCloseButton *rightBtn = new CentralTabCloseButton();
    rightBtn->setObjectName("tab-close-button");

    QToolButton *leftBtn = new QToolButton();
    leftBtn->setAttribute(Qt::WA_TransparentForMouseEvents);
    leftBtn->setObjectName("tab-icon-button");
    leftBtn->setProperty("tab-type", tab->TypeToString(tab->type()));

    bar->setTabButton(index, QTabBar::LeftSide, leftBtn);
    bar->setTabButton(index, QTabBar::RightSide, rightBtn);

    connect(rightBtn, &QAbstractButton::clicked, this,
            [=]() { emit tabCloseRequested(indexOf(tab)); });
}

void CentralTabWidget::removeTabCore(int index) {
}

void CentralTabWidget::tabIndexChangeCore(int index, bool changed) {
    Q_UNUSED(index)
    Q_UNUSED(changed)
}
